package com.xinya.wanandroidclient.adapter

import android.text.Html
import android.view.LayoutInflater
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.google.android.flexbox.FlexboxLayout
import com.xinya.wanandroidclient.R
import com.xinya.wanandroidclient.bean.NaviBean
import com.xinya.wanandroidclient.bean.SystemBean
import java.text.FieldPosition

/**
 *
 * @ClassName:      SquareFlexAdapter$
 * @Description:    java类作用描述
 * @Author:         xinya
 * @CreateDate:     2021/3/3$ 19:04$
 * @UpdateRemark:   更新内容
 * @Version:        1.0
 */
class SquareNavAdapter : BaseQuickAdapter<NaviBean, BaseViewHolder>(R.layout.item_square, null) {
    override fun convert(holder: BaseViewHolder, item: NaviBean) {
        holder.setText(R.id.tv_title, item.name)
        val flexBoxLayout = holder.getView<FlexboxLayout>(R.id.flex_box)
        flexBoxLayout.removeAllViews()
        for (child in item.articles) {
            val textView = LayoutInflater.from(flexBoxLayout.context)
                .inflate(R.layout.item_text_radius, flexBoxLayout, false) as TextView
            textView.text = Html.fromHtml(child.title)
            flexBoxLayout.addView(textView)

            textView.setOnClickListener {
                listener?.invoke(textView, child.id, child.link)
            }
        }
    }

    private var listener: ((TextView, Int, String) -> Unit)? = null
    fun setFlexChildClickListener(listener: (TextView, Int, String) -> Unit) {
        this.listener = listener
    }


}